<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/template.js"></script>
	</head>
	<body>
		
		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">

			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation"><a href="goodsList.html">商品列表</a></li>
				<li role="presentation"><a href="goodsAdd.html">添加商品</a></li>
				<li role="presentation" class="active"><a href="goodsSearch.html">商品搜索</a></li>
			</ul>
			
			<div class="admin_tab_cont" style="display:block;" id="tab1">
				<div class="input-group">
					<input type="text" class="form-control" placeholder="请输入商品编号" name="goods_id" id="goods_id">
					<span class="input-group-btn">
		        		<button class="btn btn-default" type="button" id="btn">&emsp;搜索&emsp;</button>
		      		</span>
				</div>
				<section class="table-responsive">
					<table class="table table-bordered" id='goodsSearch' style="border: 1px solid #ddd">
						<thead>
							<tr id="head">
								<th>商品ID</th>
								<th>商品名称</th>
								<th>销售价格</th>
								<th>商品数量</th>
								<th>显示条件</th>
								<th>商品介绍</th>
								<th>出售时间</th>
							</tr>
						</thead>
						<tbody></tbody>
					</table>
				</section>
			</div>
			<script type="text/html" id="tpl">
				<tr>
					<td>{{data.goods_id}}</td>
					<td>{{data.goods_name}}</td>
					<td>{{data.price}}</td>
					<td>{{data.number}}</td>
					{{if data.goods_level == 1}}
						<td>一级可见</td>
					{{/if}}
					{{if data.goods_level == 2}}
					<td>二级可见</td>
					{{/if}}
					{{if data.goods_level == 3}}
					<td>三级可见</td>
					{{/if}}
					{{if data.goods_level == 10}}
					<td>都可见</td>
					{{/if}}
					<td>{{data.description}}</td>
					<td>{{data.add_time}}</td>
				</tr>
			</script>
		</div>
		<script type="text/javascript">
			$("#btn").click(function(){
				var goods_id = $("#goods_id").val();
				if($.trim(goods_id) == '' || isNaN($.trim(goods_id))) {
					alert("商品编号错误，请重新输入!");
					return false;
				}
				var params = $("input").serialize();
				var url = "{:U('Admin/Main/goodsSearchCheck')}";
				$.ajax({
					type:"post",
					url:url,
					dataType:"json",
					data:params,
					success:function(data) {
						if(data && data != "false"){
							if(data.goods_id == goods_id) {
								data.add_time = getLocalTime(data.add_time);
								$("#goodsSearch tbody").html(template('tpl',{'data':data}));
									getEmpty(".form-control");
								}else{
									alert("请输入正确的商品编号！");
									getEmpty(".form-control");
									getFocus('.form-control');
									$("#goodsSearch tbody").html('');
								}
							}else{
								console.log(data);
								alert("请输入正确的商品编号！!!!!");
								$("#goodsSearch tbody").html('');
								getEmpty(".form-control");
								return false;
							}
					}
				});
			});
			function getFocus(obj){
				$(obj).focus();
			}
			function getEmpty(obj){
				$(obj).val('');
			}
		</script>
	</body>
</html>
